package cloud.zhixinglu.www.spring.boot.paho.mqtt.enums;

import com.fasterxml.jackson.annotation.JsonValue;
import lombok.Getter;

/**
 * 功能描述: MQTT发布Topic枚举
 * @author  LiZhaoHua WeiXin
 * @date  2022/12/30 15:53
 */
@Getter
public enum TopicEnum {

    /**
     * Topic 发布列表
     */
    CANCEL_UPGRADE_ISSUED("/ota/upgrade/cancel/issued", "取消升级下发"),
    UPGRADE_NOTIFICATION_ISSUED("/ota/upgrade/notification/issued", "升级通知下发"),


    UPGRADE_RESULT_REPORT("/ota/upgrade/progress/report", "升级结果上报"),

    DELAYED_BASE("$delayed/", "延迟消息根路径"),
    DELAYED_USER_LOGOUT_ISSUED("/user/logout/issued", "用户注销延迟消息"),

    WILL_TOPIC("will-topic", "遗嘱消息"),
    ;

    private final String topic;

    @JsonValue
    private final String describe;

    /**
     * 构造方法
     *
     * @param topic    String 主题
     * @param describe String 描述
     */
    TopicEnum(String topic, String describe) {
        this.topic = topic;
        this.describe = describe;
    }


    /**
     * 动态获取topic枚举
     *
     * @param topic String
     * @return TopicEnum
     */
    public static TopicEnum getEnum(String topic) {
        for (TopicEnum item : values()) {
            if (item.getTopic().equals(topic)) {
                return item;
            }
        }
        return null;
    }

}
